home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / stevie.arc / PARAM.C < prev    next >
Text File  |  1990-01-10  |  4KB  |  167 lines

  1. /*
  2.  * STEVIE - ST Editor for VI Enthusiasts   ...Tim Thompson...twitch!tjt...
  3.  *
  4.  * Extensive modifications by:  Tony Andrews       onecom!wldrdg!tony
  5.  * Turbo C 1.5 port by: Denny Muscatelli 061988
  6.  */
  7.  
  8. /*
  9.  * Code to handle user-settable parameters. This is all pretty much table-
  10.  * driven. To add a new parameter, put it in the params array, and add a
  11.  * macro for it in param.h. If it's a numeric parameter, add any necessary
  12.  * bounds checks to doset(). String parameters aren't currently supported.
  13.  */
  14.  
  15. #include "stevie.h"
  16.  
  17. struct    param    params[] = {
  18.  
  19.     { "tabstop",    "ts",        8,    P_NUM },
  20.     { "scroll",    "scroll",    12,    P_NUM },
  21.     { "report",    "report",    5,    P_NUM },
  22.     { "lines",    "lines",    25,    P_NUM },
  23.  
  24.     { "vbell",    "vb",        TRUE,    P_BOOL },
  25.     { "showmatch",    "sm",        FALSE,    P_BOOL },
  26.     { "wrapscan",    "ws",        TRUE,    P_BOOL },
  27.     { "errorbells",    "eb",        FALSE,    P_BOOL },
  28.     { "showmode",    "mo",        FALSE,    P_BOOL },
  29.     { "backup",    "bk",        FALSE,    P_BOOL },
  30.     { "return",    "cr",        TRUE,    P_BOOL },
  31.     { "list",    "list",        FALSE,    P_BOOL },
  32. #if 0
  33.     /* not yet implemented */
  34.     { "autoindent",    "ai",        FALSE,    P_BOOL },
  35. #endif
  36.     { "",        "",        0,    0, }        /* end marker */
  37.  
  38. };
  39.  
  40. static    void    showparms();
  41.  
  42. void
  43. doset(arg, inter)
  44. char    *arg;        /* parameter string */
  45. bool_t    inter;        /* TRUE if called interactively */
  46. {
  47.     int    i;
  48.     char    *s;
  49.     bool_t    did_lines = FALSE;
  50.  
  51.     bool_t    state = TRUE;        /* new state of boolean parms. */
  52.  
  53.     if (arg == NULL) {
  54.         showparms(FALSE);
  55.         return;
  56.     }
  57.     if (strncmp(arg, "all", 3) == 0) {
  58.         showparms(TRUE);
  59.         return;
  60.     }
  61.     if (strncmp(arg, "no", 2) == 0) {
  62.         state = FALSE;
  63.         arg += 2;
  64.     }
  65.  
  66.     for (i=0; params[i].fullname[0] != NUL ;i++) {
  67.         s = params[i].fullname;
  68.         if (strncmp(arg, s, strlen(s)) == 0)    /* matched full name */
  69.             break;
  70.         s = params[i].shortname;
  71.         if (strncmp(arg, s, strlen(s)) == 0)    /* matched short name */
  72.             break;
  73.     }
  74.  
  75.     if (params[i].fullname[0] != NUL) {    /* found a match */
  76.         if (params[i].flags & P_NUM) {
  77.             did_lines = (i == P_LI);
  78.             if (inter && (arg[strlen(s)] != '=' || state == FALSE))
  79.                 emsg("Invalid set of numeric parameter");
  80.             else {
  81.                 params[i].value = atoi(arg+strlen(s)+1);
  82.                 params[i].flags |= P_CHANGED;
  83.             }
  84.         } else /* boolean */ {
  85.             if (inter && (arg[strlen(s)] == '='))
  86.                 emsg("Invalid set of boolean parameter");
  87.             else {
  88.                 params[i].value = state;
  89.                 params[i].flags |= P_CHANGED;
  90.             }
  91.         }
  92.     } else {
  93.         if (inter)
  94.             emsg("Unrecognized 'set' option");
  95.     }
  96.  
  97.     /*
  98.      * Update the screen in case we changed something like "tabstop"
  99.      * or "list" that will change its appearance.
  100.      */
  101.     if (inter)
  102.         updatescreen();
  103.  
  104.     if (did_lines) {
  105.         Rows = P(P_LI);
  106.         screenalloc();        /* allocate new screen buffers */
  107.         screenclear();
  108.         updatescreen();
  109.     }
  110.     /*
  111.      * Check the bounds for numeric parameters here
  112.      */
  113.     if (P(P_TS) <= 0 || P(P_TS) > 32) {
  114.         if (inter)
  115.             emsg("Invalid tab size specified");
  116.         P(P_TS) = 8;
  117.         return;
  118.     }
  119.  
  120.     if (P(P_SS) <= 0 || P(P_SS) > Rows) {
  121.         if (inter)
  122.             emsg("Invalid scroll size specified");
  123.         P(P_SS) = 12;
  124.         return;
  125.     }
  126.  
  127.     /*
  128.      * Check for another argument, and call doset() recursively, if
  129.      * found. If any argument results in an error, no further
  130.      * parameters are processed.
  131.      */
  132.     while (*arg != ' ' && *arg != '\t') {    /* skip to next white space */
  133.         if (*arg == NUL)
  134.             return;            /* end of parameter list */
  135.         arg++;
  136.     }
  137.     while (*arg == ' ' || *arg == '\t')    /* skip to next non-white */
  138.         arg++;
  139.  
  140.     if (*arg)
  141.         doset(arg);    /* recurse on next parameter, if present */
  142. }
  143.  
  144. static    void
  145. showparms(all)
  146. bool_t    all;    /* show ALL parameters */
  147. {
  148.     struct    param    *p;
  149.     char    buf[64];
  150.  
  151.     gotocmd(TRUE, TRUE, 0);
  152.     outstr("Parameters:\r\n");
  153.  
  154.     for (p = ¶ms[0]; p->fullname[0] != NUL ;p++) {
  155.         if (!all && ((p->flags & P_CHANGED) == 0))
  156.             continue;
  157.         if (p->flags & P_BOOL)
  158.             sprintf(buf, "\t%s%s\r\n",
  159.                 (p->value ? "" : "no"), p->fullname);
  160.         else
  161.             sprintf(buf, "\t%s=%d\r\n", p->fullname, p->value);
  162.  
  163.         outstr(buf);
  164.     }
  165.     wait_return();
  166. }
  167.